package com.busi.controller.shop;

import java.util.List;

import com.busi.entity.Allocation;
import com.busi.entity.Consume;
import com.busi.entity.RuleSet;
import com.busi.entity.ShopRule;
import com.busi.model.Shop;
import com.busi.model.ShopService;
import com.busi.util.HttpUtils;
import com.busi.util.PropertyUtil;
import com.google.gson.reflect.TypeToken;
import com.zcurd.controller.BaseController;
/** ******************  类说明  *********************
 * class       :  ShopController
 * @author     :  xusai
 * @version    :  1.0  
 * description :  商户管理
 * @see        :                        
 * 
 * ***********************************************
 * */
public class ShopController extends BaseController {

	/**
	 * ******************  方法说明  ********************
	 * @methodname :  list
	 * @author     :  xusai
	 * @version    :  1.0  
	 * @description:  商家用户列表查询详细
	 * @see        :     
	 * ***********************************************
	 * */
	public void list() {
		render("list.html");
	}
	public void listData() {
		Shop shop = getBean(Shop.class, "");
		String body = gson.toJson(shop);
		String domain = PropertyUtil.getStrValue("new_zx.domain", "");
		String url = domain + "/api/shop/findList";
		String[][] headers = { { "Content-Type", "application/json" } };
		String jsonString = HttpUtils.doPost(url, body, headers, 3, 5, "utf-8");
		renderJson(jsonString == null ? "" : jsonString);
	}

	/**
	 * ******************  方法说明  ********************
	 * @methodname :  addPage
	 * @author     :  xusai
	 * @version    :  1.0  
	 * description :  新增商户
	 * @see        :     
	 * ***********************************************
	 * */
	public void addPage() {
		render("add.html");
	}
	public void add() {
		Shop shop = getBean(Shop.class, "");
		String body = gson.toJson(shop);
		String domain = PropertyUtil.getStrValue("new_zx.domain", "");
		String url = domain + "/api/shop/add";
		String[][] headers = { { "Content-Type", "application/json" } };
		String jsonString = HttpUtils.doPost(url, body, headers, 3, 5, "utf-8");
		LOG.info("add"+jsonString);
		render("list.html");
	}
	
	/**
	 * ******************  方法说明  ********************
	 * @methodname :  detailpageList
	 * @author     :  xusai
	 * @version    :  1.0  
	 * description :  商户详细
	 * @see        :     
	 * ***********************************************
	 * */
	public void detail2(){
		render("detailpage.html");
	}
	public void detailpageList() {
		Shop shop = getBean(Shop.class, "");
		ShopService ss = new ShopService();
		ss.setSetId(shop.getSetId());
		ss.setId(shop.getId());
		String body = gson.toJson(ss);
		String domain = PropertyUtil.getStrValue("new_zx.domain", "");
		String url = domain + "/api/shop/detailpages";
		String[][] headers = { { "Content-Type", "application/json" } };
		String jsonString = HttpUtils.doPost(url, body, headers, 3, 5, "utf-8");
		List<ShopService> list = gson.fromJson(jsonString, new TypeToken<List<ShopService>>() {
		}.getType());
		for (int i = 0; i < list.size(); i++) {
			ShopService s = list.get(i);
			if (s.getServiceId().equals("1")) {
				s.setServiceId("反欺诈");
			}
			if (s.getServiceId().equals("2")) {
				s.setServiceId("评分卡");
			}
		}
		if (list.size() >= 2) {
			shop.setServiceId(list.get(0).getServiceId() + "," + list.get(1).getServiceId());
		} else {
			shop.setServiceId(list.get(0).getServiceId());
		}

		shop.setUsername(list.get(0).getSetName());
		shop.setRemarks(shop.getSetId());
		setAttr("shop", shop);
		render("detailpage.html");
	}
	public void detailpage() {
		Shop shop = getBean(Shop.class, "");
		String body = gson.toJson(shop);
		String domain = PropertyUtil.getStrValue("new_zx.domain", "");
		String url = domain + "/api/shop/findOne";
		String[][] headers = { { "Content-Type", "application/json" } };
		String jsonString = HttpUtils.doPost(url, body, headers, 3, 5, "utf-8");
		renderJson(jsonString == null ? "" : jsonString);
	}
	/**
	 * ******************  方法说明  ********************
	 * @methodname :  update  
	 * @author     :  xusai
	 * @version    :  1.0  
	 * @description:  充值记录修改先查后改
	 * @see        :     
	 * ***********************************************
	 * */
	public void update() {
		Shop shop =getBean(Shop.class,"");
		String body = gson.toJson(shop);
		String domain = PropertyUtil.getStrValue("new_zx.domain", "");
		String url = domain + "/api/shop/findOne";
		String[][] headers = {{"Content-Type", "application/json"}};
		String jsonString = HttpUtils.doPost(url, body, headers , 3, 5, "utf-8");
		LOG.info("update()查询充值金额："+jsonString);
		List<Shop> shop2=gson.fromJson(jsonString, new TypeToken<List<Shop>>() {
		}.getType());
		shop.setCreateTime(shop2.get(0).getCreateTime());
		setAttr("shop", shop);
		render("update.html");
	}
	/**
	 * ******************  方法说明  ********************
	 * @methodname :  updatePage  
	 * @author     :  xusai
	 * @version    :  1.0  
	 * @description:  修改页面
	 * @see        :     
	 * ***********************************************
	 * */
	public void updatePage() {
		Shop shop = getBean(Shop.class,"");
		String body = gson.toJson(shop);
		String domain = PropertyUtil.getStrValue("new_zx.domain", "");
		String[][] headers = {{"Content-Type", "application/json"}};
		String url = domain + "/api/shop/updatePage";
		String jsonString = HttpUtils.doPost(url, body, headers, 3, 5, "utf-8");
		renderJson(jsonString == null ? "" : jsonString);
		renderSuccess();
	}
	/**
	 * ******************  方法说明  ********************
	 * @methodname :  find  
	 * @author     :  xusai
	 * @version    :  1.0  
	 * description :  通过ajax显示规则集
	 * @see        :     
	 * ***********************************************
	 * */
	public void find() {
		RuleSet ruleSet = getBean(RuleSet.class, "");
		String body = gson.toJson(ruleSet);
		String domain = PropertyUtil.getStrValue("new_zx.domain", "");
		String url = domain + "/api/shop/find";
		String[][] headers = { { "Content-Type", "application/json" } };
		String jsonString = HttpUtils.doPost(url, body, headers, 3, 5, "utf-8");
		renderJson(jsonString == null ? "" : jsonString);
	}

	/**
	 * ******************  方法说明  ********************
	 * @methodname :  allocation  
	 * @author     :  xusai
	 * @version    :  1.0  
	 * @description :  产品价格配置
	 * @see        :     
	 * ***********************************************
	 * */
	public void allocation() {
		Shop shop = getBean(Shop.class,"");
		shop.setRemarks(shop.getSetId());
		setAttr("shop", shop);
		render("allocation.html");
	}
	/**
	 * ******************  方法说明  ********************
	 * @methodname :  addAllocation  
	 * @author     :  xusai
	 * @version    :  1.0  
	 * @description :  增加页面产品价格配置
	 * @see        :     
	 * ***********************************************
	 * */
	public void addAllocation() {
		Allocation allocation=getBean(Allocation.class,"");
		Shop shop = getBean(Shop.class,"");
		String body = gson.toJson(allocation);
		String domain = PropertyUtil.getStrValue("new_zx.domain", "");
		String url = domain + "/api/shop/addAllocation";
		String[][] headers = {{"Content-Type", "application/json"}};
		String jsonString = HttpUtils.doPost(url, body, headers , 3, 5, "utf-8");
		LOG.info("#addAllocation()添加产品价格配置"+jsonString);
		setAttr("shop", shop);
		render("detailpage.html");
	}
	/**
	 * ******************  方法说明  ********************
	 * @methodname :  searchPrice
	 * @author     :  xusai
	 * @version    :  1.0  
	 * @description:  获取数据字典价格配置
	 * @see        :     
	 * ***********************************************
	 * */
	//获取数据字典价格配置
	public void searchPrice(){
		Shop shop=getBean(Shop.class,"");
		String body = gson.toJson(shop);
		String domain = PropertyUtil.getStrValue("new_zx.domain", "");
		String url = domain + "/api/shop/searchPrice";
		String[][] headers = {{"Content-Type", "application/json"}};
		String jsonString = HttpUtils.doPost(url, body, headers , 3, 5, "utf-8");
		renderJson(jsonString==null?"":jsonString);		
	}
	/**
	 * ******************  方法说明  ********************
	 * @methodname :  searchShopId 
	 * @author     :  xusai
	 * @version    :  1.0  
	 * @description:  查询shopId
	 * @see        :     
	 * ***********************************************
	 * */
	public void searchShopId(){
		Shop shop=getBean(Shop.class,"");
		String body = gson.toJson(shop);
		String domain = PropertyUtil.getStrValue("new_zx.domain", "");
		String url = domain + "/api/shop/searchShopId";
		String[][] headers = {{"Content-Type", "application/json"}};
		String jsonString = HttpUtils.doPost(url, body, headers , 3, 5, "utf-8");
		renderJson(jsonString==null?"":jsonString);		
	}
	/**
	 * ******************  方法说明  ********************
	 * @methodname :  updateAllocation 
	 * @author     :  xusai
	 * @version    :  1.0  
	 * @description:  修改产品价格配置
	 * @see        :     
	 * ***********************************************
	 * */
	//修改产品价格配置
	public void updateAllocation(){
		Shop shop = getBean(Shop.class,"");
		String body = gson.toJson(shop);
		String domain = PropertyUtil.getStrValue("new_zx.domain", "");
		String[][] headers = {{"Content-Type", "application/json"}};
		String url = domain + "/api/shop/updateAllocation";
		String jsonString = HttpUtils.doPost(url, body, headers, 3, 5, "utf-8");
		LOG.info("#updateAllocation()修改产品价格配置"+jsonString);
		shop.setRemarks(shop.getSetId());
		setAttr("shop", shop);
		render("detailpage.html");
	}
	/**
	 * ******************  方法说明  ********************
	 * @methodname :  recharge  
	 * @author     :  xusai
	 * @version    :  1.0  
	 * @description:  充值记录
	 * @see        :     
	 * ***********************************************
	 * */
	public void recharge() {
		Shop shop = getBean(Shop.class,"");
		setAttr("shop", shop);
		render("recharge.html");
	}
	
	/**
	 * ******************  方法说明  ********************
	 * @methodname :  consume  
	 * @author     :  xusai
	 * @version    :  1.0  
	 * @description:  消费记录
	 * @see        :     
	 * ***********************************************
	 * */
	public void consume() {
		Shop shop = getBean(Shop.class,"");
		setAttr("shop", shop);
		render("consume.html");
	}
	public void consumeDetail() {
		Consume consume = getBean(Consume.class, "");
		String body = gson.toJson(consume);
		String domain = PropertyUtil.getStrValue("new_zx.domain", "");
		String url = domain + "/api/shop/consumeDetail";
		String[][] headers = { { "Content-Type", "application/json" } };
		String jsonString = HttpUtils.doPost(url, body, headers, 3, 5, "utf-8");
		renderJson(jsonString == null ? "" : jsonString);
	}
	/**
	 * ******************  方法说明  ********************
	 * @methodname :  addAllocation  
	 * @author     :  xusai
	 * @version    :  1.0  
	 * @description:  查看规则集
	 * @see        :     
	 * ***********************************************
	 * */
	public void search(){
		Shop shop = getBean(Shop.class,"");
		shop.setRemarks(shop.getSetId());
		setAttr("shop", shop);
		render("searchRule.html");
	}
	/**
	 * ******************  方法说明  ********************
	 * @methodname :  detailList  
	 * @author     :  xusai
	 * @version    :  1.0  
	 * @description :  规则集详情回显列表
	 * @see        :     
	 * ***********************************************
	 * */
	public void detailList(){
		ShopRule shopRule=getBean(ShopRule.class,"");
		setAttr("setId", shopRule.getSetId());
		String body = gson.toJson(shopRule);
		String domain = PropertyUtil.getStrValue("new_zx.domain", "");
		String url = domain + "/api/shop/findRuleList";
		String[][] headers = {{"Content-Type", "application/json"}};
		String jsonString = HttpUtils.doPost(url, body, headers , 3, 5, "utf-8");
		renderJson(jsonString==null?"":jsonString);
	}
	/**
	 * ******************  方法说明  ********************
	 * @methodname :  detailRule  
	 * @author     :  xusai
	 * @version    :  1.0  
	 * @description :  导入规则
	 * @see        :     
	 * ***********************************************
	 * */
	public void detailRule(){
		Shop shop = getBean(Shop.class,"");
		shop.setRemarks(shop.getSetId());
		setAttr("shop", shop);
		render("rule.html");
	}
	/**
	 * ******************  方法说明  ********************
	 * @methodname :  detailDataList  
	 * @author     :  xusai
	 * @version    :  1.0  
	 * @description :  规则详情回显列表
	 * @see        :     
	 * ***********************************************
	 * */
	public void detailDataList(){
		ShopRule shopRule=getBean(ShopRule.class,"");
		setAttr("setId", shopRule.getSetId());
		String body = gson.toJson(shopRule);
		String domain = PropertyUtil.getStrValue("new_zx.domain", "");
		String url = domain + "/api/shop/findDataList";
		String[][] headers = {{"Content-Type", "application/json"}};
		String jsonString = HttpUtils.doPost(url, body, headers , 3, 5, "utf-8");
		renderJson(jsonString==null?"":jsonString);		
	}
	/**
	 * ******************  方法说明  ********************
	 * @methodname :  datasave  
	 * @author     :  xusai
	 * @version    :  1.0  
	 * @description :  添加规则
	 * @see        :     
	 * ***********************************************
	 * */
	public void datasave(){
		ShopRule shopRule=getBean(ShopRule.class,"");
		shopRule.setDataId(shopRule.getDataarr());
		String body = gson.toJson(shopRule);
		String domain = PropertyUtil.getStrValue("new_zx.domain", "");
		String url = domain + "/api/shop/datasavePage";
		String[][] headers = {{"Content-Type", "application/json"}};
		String jsonString = HttpUtils.doPost(url, body, headers , 3, 5, "utf-8");
		LOG.info("datasave()添加规则："+jsonString);
		shopRule.setRemarks(shopRule.getSetId());
		setAttr("shop", shopRule);
		shopRule.setId(shopRule.getShopId());
		render("searchRule.html");
	}
	/**
	 * ******************  方法说明  ********************
	 * @methodname :  delete  
	 * @author     :  xusai
	 * @version    :  1.0  
	 * @description:  删除规则
	 * @see        :     
	 * ***********************************************
	 * */
	public void delete(){
		ShopRule shopRule = getBean(ShopRule.class,"");
		String body = gson.toJson(shopRule);
		String domain = PropertyUtil.getStrValue("new_zx.domain", "");
		String url = domain + "/api/shop/deletePage";
		String[][] headers = {{"Content-Type", "application/json"}};
		String jsonString = HttpUtils.doPost(url, body, headers, 3, 5, "utf-8");
		LOG.info("delete()删除规则："+jsonString);
		renderSuccess();
	}
	/**
	 * ******************  方法说明  ********************
	 * @methodname :  updateStore  
	 * @author     :  xusai
	 * @version    :  1.0  
	 * @description:  修改分值
	 * @see        :     
	 * ***********************************************
	 * */
	public void updateStore() {
		ShopRule shopRule = getBean(ShopRule.class,"");
		String body = gson.toJson(shopRule);
		String domain = PropertyUtil.getStrValue("new_zx.domain", "");
		String url = domain + "/api/shop/findStore";
		String[][] headers = {{"Content-Type", "application/json"}};
		String jsonString = HttpUtils.doPost(url, body, headers, 3, 5, "utf-8");
		LOG.info("updateStore()查询分值："+jsonString);
		ShopRule shopRule2 = gson.fromJson(jsonString, ShopRule.class);
		shopRule2.setRemarks(shopRule.getSetId());
		shopRule2.setBalance(shopRule.getBalance());
		shopRule2.setSearchNumber(shopRule.getSearchNumber());
		shopRule2.setName(shopRule.getName());
		setAttr("shopRule", shopRule2);
		render("updateStore.html");
	}
	public void updateStorePage() {
		ShopRule shopRule = getBean(ShopRule.class,"");
		String body = gson.toJson(shopRule);
		String domain = PropertyUtil.getStrValue("new_zx.domain", "");
		String url = domain + "/api/shop/updateStore";
		String[][] headers = {{"Content-Type", "application/json"}};
		String jsonString = HttpUtils.doPost(url, body, headers, 3, 5, "utf-8");
		LOG.info("updateStorePage()修改分值："+jsonString);
		renderSuccess();
	}
	
	
}
